package org.zfes.snowier.common.monitor.http.response;


import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

public class HeaderResponse  implements Serializable{
			
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	private Map<String, List<String>> headers;
	
    private int statusCode;

    private String error;
    
    
    public HeaderResponse() {
      
    }
    
    public HeaderResponse(int statusCode) {
        this.statusCode = statusCode;
    }
    
    public HeaderResponse(Map<String, List<String>> headers, int statusCode) {
        this.statusCode = statusCode;
        this.headers = headers;
    }
    public List<String> getHeader(String name) {
    	return headers.get(name);
    }
	public Map<String, List<String>> getHeaders() {
		return headers;
	}
	public HeaderResponse setHeaders(Map<String, List<String>> headers) {
		this.headers = headers;
		return this;
	}
	public int getStatusCode() {
		return statusCode;
	}

	public HeaderResponse setStatusCode(int statusCode) {
		this.statusCode = statusCode;
		return this;
	}
	
	
	
	
	
	public String getError() {
		return error;
	}

	public HeaderResponse setError(String error) {
		this.error = error;
		return this;
	}

	public boolean isok() {
        return 200==statusCode;
    }
	
	public <T> HeaderResponse isok(Consumer<? super Map<String, List<String>>> consumer) {
        if (200==statusCode) {
        	 consumer.accept(headers);
        }

		return this;
    }
	
	
	 public HeaderResponse orElse(Consumer<? super HeaderResponse> consumer) {
		 if (200!=statusCode) {
        	 consumer.accept(this);
        }
		 return this;
	 }
	 public  HeaderResponse orElseThrow(Exception e)  {
		 try {
			throw e;
		} catch (Exception e1) {
			
		}
		 return this;
	 }
	 

	@Override
	public String toString() {
		return "HeaderResponse [headers=" + headers + ", statusCode=" + statusCode + "]";
	}
	
 
    
}
